package com.h117121.fashionshop.core.dom;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;

@SuppressWarnings("serial")
@Entity
@Table(name = "ProductType")
public class ProductType extends BaseDom {
	@Column(name = "Name", length = 250, unique = true, nullable = false)
	private String name;

	@Column(name = "Description", length = 1000, nullable = true)
	private String description;

	@OneToMany(mappedBy = "type", fetch = FetchType.LAZY)
	@Cascade({ org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
	private Set<Product> products;

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @param description
	 *            the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	public String getNameUrl() throws UnsupportedEncodingException {
		return URLEncoder.encode(name, "UTF-8");
	}

	public Set<Product> getProducts() {
		return products;
	}

	public void setProducts(Set<Product> products) {
		this.products = products;
	}
}